
package edu.tongji.jiaowu.dao.jdbc;
 
import java.util.List;

import edu.tongji.jiaowu.dao.CourseDao;
import com.tongji.quickCRUDQ.define.Row;
import com.tongji.quickCRUDQ.model.CommonBean;
import com.tongji.quickCRUDQ.dao.jdbc.BaseDaoJdbc;
import com.tongji.quickCRUDQ.exception.FormatException;

public class CourseDaoJdbc extends BaseDaoJdbc implements CourseDao {
	String tableName="T_COURSE";
	String beanName="course";
	
	public CommonBean createCourse(){
		CommonBean courses=this.createBean(tableName,beanName);
                return courses;		
	}
	
/*
	public CommonBean findCourses(String refid) {
		CommonBean courses=this.createCourse();
		String sql="select * from T_COURSE where refid=?";
		List data=this.getCommonDao().select(sql,new String[]{refid});
		courses.addData(data);
                return courses;
       }
*/
	public CommonBean findCourseById(String id) {
		CommonBean courses=this.createCourse();
		String sql="select * from T_COURSE where id=?";
		List data=this.getCommonDao().select(sql,new String[]{id});
		courses.addData(data);
    return courses;
  }
  
	public CommonBean findAllCourses() {
		CommonBean courses=this.createCourse();
		String sql="select * from T_COURSE ";
		List data=this.getCommonDao().select(sql,new String[]{});
		courses.addData(data);
    return courses;
  }
	public void insertCourse(CommonBean courseBean){
		List data=courseBean.getData();
		Row row=this.getRow(tableName);
		this.getCommonDao().templateBatchInsert(row,data,this.getIdGenerator());
	}

	public CommonBean findCourseByNo(String courseNo) {
		String sql="select * from t_course where course_no=?";
		List data=getCommonDao().select(sql, new String[]{courseNo});
		if (data.size()==0) {
			throw new FormatException("无此课号:"+courseNo);
		}
		CommonBean course=createCourse();
		course.addData(data);
		return course;
	}
}

